package jsyf.oa.web.wreport;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.wreport.WReportUnfinishFacade;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.util.List;

/**
 * Created by WHH-PC on 2018/1/15.
 */
@Api(value = "未关闭事项接口", description = "未关闭事项接口")
@Controller
@RequestMapping("/wreportUnfinish")
public class WReportUnfinishController {
    @Resource
    private WReportUnfinishFacade wReportUnfinishFacade;

    @RequestMapping(value = "/save.json", method = RequestMethod.POST)
    public void save(HttpServletResponse response, @RequestBody String jsonData) {
        String id = wReportUnfinishFacade.save(jsonData);
        JSONObject objResult = new JSONObject();
        objResult.put("id", id);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(objResult));
    }

    @RequestMapping(value = "/saveUnfinish.json", method = RequestMethod.POST)
    public void saveUnfinish(HttpServletResponse response, @RequestBody String jsonData) {
        String id = wReportUnfinishFacade.saveUnfinishMain(jsonData);
        JSONObject objResult = new JSONObject();
        objResult.put("id", id);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(objResult));
    }


    @RequestMapping(value = "/getWReportUnfinishCount.json", method = RequestMethod.POST)
    public void getWReportUnfinishCount(HttpServletResponse response, @RequestBody String jsonData) {
        List<JSONObject> jsonObjectList = wReportUnfinishFacade.getWReportUnfinishCount();
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(jsonObjectList));
    }

    @RequestMapping(value = "/getWReportUnfinishMainList.json", method = RequestMethod.POST)
    public void getWReportUnfinishMainList(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject object = JSON.parseObject(jsonData);
        JSONObject jsonObject = wReportUnfinishFacade.getWReportUnfinishMainList(object);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(jsonObject));
    }

    @RequestMapping(value = "/getWReportUnfinishListByMainId.json", method = RequestMethod.POST)
    public void getWReportUnfinishListByMainId(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject object = JSON.parseObject(jsonData);
        List<JSONObject> list = wReportUnfinishFacade.getWReportUnfinishListByMainId(object);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(list));
    }

    @RequestMapping(value = "/getWReportUnfinishViewListByPage.json", method = RequestMethod.POST)
    public void getWReportUnfinishViewListByPage(HttpServletResponse response,@RequestBody String jsonData){
        JSONObject object = JSON.parseObject(jsonData);
        List<JSONObject> list = wReportUnfinishFacade.getWReportUnfinishViewListByPage(object);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(list));
    }
    @ResponseBody
    @ApiOperation(
            value = "点击关闭按钮",
            notes = "关闭事项及原因",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE
    )
    @ApiImplicitParam(
            name = "jsonData",
            value = "{trackContent:\"xxxx\",overReason:\"提前结束\",id:\"2017121617134046A7B447526DBB055C\"}",
            dataType = "String",
            paramType = "body"
    )
    @RequestMapping(value = "/overWReportUnfinishMain.json",method = RequestMethod.POST)
    public void overWReportUnfinishMain(HttpServletResponse response,@RequestBody String jsonData){
        String id = wReportUnfinishFacade.overWReportUnfinishMain(jsonData);
        JSONObject objResult = new JSONObject();
        objResult.put("id", id);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(objResult));
    }

    @RequestMapping(value = "/getWReportUnfinishReply.json", method = RequestMethod.POST)
    public void getWReportUnfinishReply(HttpServletResponse response,@RequestBody String jsonData){
        JSONObject object = JSON.parseObject(jsonData);
        String trackId = object.getString("trackId");
        List<JSONObject> list = wReportUnfinishFacade.getWReportUnfinishReply(trackId);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrTimeRespond(list));
    }

    @RequestMapping(value = "/addTrack.json", method = RequestMethod.POST)
    public void addTrack (HttpServletResponse response,@RequestBody String jsonData){
        JSONObject object = JSON.parseObject(jsonData);
        String id = wReportUnfinishFacade.addTrack(object);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(id));
    }

    @RequestMapping(value = "/addReply.json", method = RequestMethod.POST)
    public void addReply (HttpServletResponse response,@RequestBody String jsonData){
        JSONObject object = JSON.parseObject(jsonData);
        String id = wReportUnfinishFacade.addReply(object);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(id));
    }

    @RequestMapping(value = "/closeMatter.json", method = RequestMethod.POST)
    public void closeMatter (HttpServletResponse response,@RequestBody String jsonData){
        JSONObject object = JSON.parseObject(jsonData);
        String id = wReportUnfinishFacade.closeMatter(object);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(id));
    }
}
